home *** CD-ROM | disk | FTP | other *** search
-
- #include "parody.h"
- #include <stdlib.h>
-
- enum ClassIdent {
- FIELDS_SETUP=123,
- ATTRIBUTE_SETUP,
- CARD_INFO
- };
-
- Parody *theDatabase = NULL;
-
-
- // Generic Integer Key.
-
- class IntKey : public Key {
- int _key;
-
- int operator>( Key &key ) { return _key>((IntKey &) key).key(); }
- int operator==( Key &key ) { return _key==((IntKey &) key).key(); }
-
- Key& operator=( Key &key ) {
- if ( this != &key ) {
- Key::operator=(key);
- IntKey& intKey = (IntKey&) key;
- _key = intKey._key;
- }
- return *this;
- }
-
-
- void Write( fstream& ndx ) { cerr << "(" << (long)this << ")"<<"IntKey::Write: "<<_key <<endl; ndx.write( (char *) &_key, sizeof _key ); }
- void Read( fstream& ndx ) { cerr << "IntKey::Read: "<<_key <<endl;ndx.read( (char *) &_key, sizeof _key ); }
-
- Key *Make() { return new IntKey(); }
- pBool isNullValue() { return (pBool) ( _key==0 ); }
-
- public:
- IntKey( int key=0 ) { cerr << "(" << (long)this << ")"<<"IntKey::IntKey("<<key<<")\n";_key = key; }
- int key() const { return _key; }
- };
-
-
- class C : public Persistent {
-
- private:
- IntKey _key;
-
- char* _s;
-
- protected:
- void Read();
- void Write();
-
- public:
- C( int id=0 );
- ~C();
-
- const char* s() { return _s; }
- const char* s( const char* news ) { _s = strdup( news ); return _s; }
-
- };
-
-
- C::C( int id ) : Persistent( *theDatabase, FIELDS_SETUP ), _key( id )
- {
- _s = strdup( "Nothing" );
- cerr <<"C::C:_key = "<<_key.key()<<endl;
- LoadObject();
- }
-
- C::~C()
- {
- cerr << "SaveObject\n";
-
- SaveObject();
- cerr << "C::~C:_key: " << _key.key() << endl;
- delete _s;
- }
-
- void
- C::Read()
- {
- pString ss;
- ReadObject( ss );
- delete _s;
- _s = strdup( ss );
- cerr << "C::Read: " << _s << "\n";
- }
-
- void
- C::Write()
- {
- cerr << "C::Writing... " << _s << "\n";
- WriteObject( pString( _s ) );
- }
-
-
- main( int argc, char** argv )
- {
- theDatabase = new Parody( "FOO" );
-
- C *c = new C( 5 );
-
- if ( c->ObjectExists() ) {
- cerr << "Content: " << c->s() << endl;
- } else {
- cerr << "Adding object...\n";
- c->AddObject();
- }
-
- if ( argc==2 ) {
- c->s( argv[ 1 ] );
- c->ChangeObject();
- }
-
- delete c;
- delete theDatabase;
- }
-